//C07:AssociativeBasics.cpp {-bor}
// Basic operations with sets and maps:
// {L} Noisy
#include <cstddef>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <utility>
#include "Noisy.h"
using namespace std;

int main(void)
{
    Noisy na[7];
    // Add elements via constructor
    set<Noisy> ns(na, na + sizeof na / sizeof(Noisy));
    Noisy n; 
    ns.insert(n);    // Originary insertion
    cout << endl;

    // Check for set membership:
    cout << "ns.count(n) = " << ns.count(n) << endl;
    if(ns.find(n) != ns.end())
    {
        cout << "n(" << n << ") found in ns" << endl;
    }

    // Print element:
    copy(ns.begin(), ns.end(),
        ostream_iterator<Noisy>(cout, " "));
    cout << endl;
    cout << "\n--------------" << endl;
    map<int, Noisy> nm;    
    for (int i = 0; i < 10; i++)
    {
        nm[i];   // Automatically makes pairs
    }
    cout << "\n-----------" << endl;
    for (size_t j = 0; j < nm.size(); j++)
    {
        cout << "nm[" << j << "] = " << nm[j] << endl;
    }

    cout << "\n---------" << endl;
    nm[10] = n;
    cout << "\n---------" << endl;
    nm.insert(make_pair(47, n));

    cout << "\n-------------" << endl;
    cout << "\n nm.count(10) = " << nm.count(10) << endl;
    cout << "nm.count(11) = " << nm.count(11) << endl;
    map<int, Noisy>::iterator it = nm.find(6);
    if(it != nm.end())
    {
        cout << "value:" << (*it).second
             << " found in nm at location 6" << endl;
        cout << "\n------------" << endl;     
    }

}